<?php
	// -----------   Page Vars    ----------
	$to_root = '';
	$authorized = null;
	$menu_selected = -1;
	$login = true;
	
	//  ---- init
	include($to_root.'_classes/init.php');
	
	$main = new ViewDescriptor('login');
		
	/* ========   INSERT CODE HERE   ======== */
	
	if(isset($_POST['name']) && isset($_POST['password'])){
		$name = $_POST['name'];
		$pwd = $_POST['password'];
		
		if($GLOBALS['User']->login(array('nick'=>$name, 'pwd'=>$pwd))){
			header('Location: index.php');
		} else {
			$GLOBALS['Messages'][] = '<span class="msg_error">'.$GLOBALS['Localization']['User']['LOGIN_ERROR'][$GLOBALS['Localization']['language']].'</span>';
		}
	}
	
	/* ========   NORMAL STUFF   ========= */
	// Messages
	if(isset($_GET['msg']) && isset($errors) && is_array($errors) && isset($error_class) && is_array($error_class)){
    	$get_msg = explode('|', $_GET['msg']);
    	foreach($get_msg as $error){
    		if(isset($errors[$error]) && isset($error[$GLOBALS['Localization']['language']])){
    			$GLOBALS['Messages'][] = '<span class="msg_'.$error_class[$error].'">'.$errors[$error].'</span>';
    		}
    	}
    }
    // render Main Template
	Template::generateMenu($main, $menu_selected);
	$main->addValue('messages', implode("\n", $GLOBALS['Messages']));
	$main->addValue('script', '');
	$main->addValue('style', '');
	
	echo $main->render(); 
?>